#coding:utf-8

from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice
import os
#连接设备(等待时间，‘版本号’)
device = MonkeyRunner.waitForConnection(1,'650e970b7d93')

result = device.takeSnapshot()
result= result.getSubImage((470,309,108,30))

result.writeToFile('D:\\python_file\\monkeyrunner\\test4.png','png')

#os.system("python D:\python_file\ocr_test\png.py")
#调用py,
code1=os.popen("python D:\python_file\ocr_test\png.py")

a=code1.read().strip('\n')
print(a)
#字符串编码问题
#判断循环
'''
while a!='王耆96区':
    device.touch(645,465,'DOWN_AND_UP')
    device.drag((645,465),(645,400),1)
    MonkeyRunner.sleep(0.2)
    result = device.takeSnapshot()
    result= result.getSubImage((470,309,108,30))
    result.writeToFile('D:\\python_file\\monkeyrunner\\test4.png','png')
    code1=os.popen("python D:\python_file\ocr_test\png.py")
    print(code1.read())
elif a=='王耆96区':
    print('ok2')
else :
    print(error)

'''


while 1:
    if a.encode('utf-8')!='王耆96区':
        print(len(a.encode('utf-8')))
        print(len(a))
        print(len('王耆96区'))
        break
    else:
        device.touch(645,465,'DOWN_AND_UP')
        device.drag((645,465),(645,400),1)
        MonkeyRunner.sleep(0.2)
        result = device.takeSnapshot()
        result= result.getSubImage((470,309,108,30))
        result.writeToFile('D:\\python_file\\monkeyrunner\\test4.png','png')
        code1=os.popen("python D:\python_file\ocr_test\png.py")
        print(code1.read())
















'''

#第一个截图
pic=device.takeSnapshot()
#获取指定区域的图像(0,57,715,1123)，注意两个括号
pic= pic.getSubImage((0,57,715,1123))
pic.writeToFile('D:\\python_file\\monkeyrunner\\test.png','png')


#等待时间
print("Wait 2s")
logFile.write("Wait 2s")
MonkeyRunner.sleep(2)

#滑动屏幕;
for i in range(1,70):
    device.drag((250,850),(250,110),0.1,10)
#开始，结束，持续时间，步骤  
    device.drag((250,110),(250,850),0.1,10)
MonkeyRunner.sleep(1)

#触击屏幕;
device.touch(507,72,"DOWN_AND_UP")



'''
